Page({
  data: {
    cartList: [
      {
        shopId: 1,
        shopName: '两句服饰旗舰店',
        goods: [
          {
            id: 1,
            img: '/pages/goodsDetail/1749115285878.png',
            title: 'NASA联名卡通小狗短袖T恤男女2025夏季新款宽松休闲',
            spec: 'M号',
            price: 59.9,
            num: 1
          }
        ]
      },
      {
        shopId: 2,
        shopName: 'ARISEISM',
        goods: [
          {
            id: 2,
            img: '/pages/goodsDetail/1749115306067.png',
            title: 'Ariseism 美式复古长袖T恤女春季新款宽松上衣',
            spec: 'M号',
            price: 105,
            num: 1
          }
        ]
      }
    ],
    recommend: [
      { id: 1, img: '/pages/cart/1749356212377.png', title: '米哈游/崩坏：星穹铁道光年刻录2025双周历', price: 89 },
      { id: 2, img: '/pages/cart/1749356390769.png', title: 'moeyu初音未来甜然梦景马克杯', price: 39 }
    ],
    totalPrice: 164.9
  },
  changeNum(e) {
    const { shop, id, type } = e.currentTarget.dataset;
    let cartList = this.data.cartList.map(shopItem => {
      if (shopItem.shopId == shop) {
        shopItem.goods = shopItem.goods.map(good => {
          if (good.id == id) {
            if (type === 'plus') good.num++;
            if (type === 'minus' && good.num > 1) good.num--;
          }
          return good;
        });
      }
      return shopItem;
    });
    this.setData({ cartList }, this.calcTotal);
  },
  calcTotal() {
    let total = 0;
    this.data.cartList.forEach(shop => {
      shop.goods.forEach(good => {
        total += good.price * good.num;
      });
    });
    this.setData({ totalPrice: total.toFixed(2) });
  },
  onLoad() {
    this.calcTotal();
  },
  goOrderConfirm() {
    wx.navigateTo({ url: '/pages/orderConfirm/orderConfirm' });
  }
}); 